Passed
Push — master ( 2b6a8e...496337 )
by Felipe Catão do
06:39
created

index.js ➔ listPage   A

Complexity

Conditions 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 4
1
import EngineApp from '../../Framework/engine.js'
2
import cards from './components/cards.js'
3
import welcomeguide from './components/welcomeGuide.js'
4
import menu from './components/menu.js'
5
import error from './components/error.js'
6
import listCards from './components/listCards.js'
7
let eng = new EngineApp()
8
9
menu() //Render Menu 
10
eng.renderEngine.registerDinamicPage("dinamicType")
11
//Add rota
12
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/","initialPage")
13
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pageInitial",welcome)
14
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs",docsPage)
15
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs/erro",error) 
16
eng.routesEngine.registerRoute("http://127.0.0.1:5500/project/index.html#pages/docs/list",listPage) 
17
//para redirecionar a rota inicial
18
eng.routesEngine.runRoute("http://127.0.0.1:5500/project/index.html","http://127.0.0.1:5500/project/index.html#pageInitial")
19
20
function welcome(){
21
    welcomeguide("Felipe")
22
}
23
24
//procurar paginação de documentos
25
function docsPage(){
26
    eng.renderEngine.clearPage()
27
    cards()
28
    if(eng.routesEngine.routePropsVars[0]!=undefined){
0 ignored issues
show
Best Practice introduced by
Comparing eng.routesEngine.routePropsVars.0 to undefined using the != operator is not safe. Consider using !== instead.
Loading history...
29
        Api(eng.routesEngine.routePropsVars[0])
30
    }
31
    else{
32
        eng.renderEngine.clearPage()
33
        error()
34
    }
35
}
36
//quando modificar o campo de  procura 
37
eng.routesEngine.whenChange(searchGuide,"searchGuide")
38
39
function searchGuide(){
40
   let searchArgs = document.getElementById("searchGuide").value.length
41
   if(searchArgs>0){
42
    eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pages/docs="+searchArgs)
43
   }
44
   else{
45
       eng.renderEngine.clearPage()
46
       eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pages/docs/erro")
47
   }
48
}
49
50
function listPage(){
51
    eng.renderEngine.clearPage()
52
    listCards()
53
    for (let index = 1; index < 20; index++) {
54
        fetch('https://jsonplaceholder.typicode.com/posts/' + index)
55
        .then(response => response.json())
56
        .then(json => eng.renderEngine.renderHtml("ListGroup","<li class='list-group-item'>"+json.title+"</li>"))
57
    }
58
}
59
60
document.getElementById("idHome").addEventListener("click",GoMainHome,false)
61
document.getElementById("listprod").addEventListener("click",listPage,false)
62
63
function GoMainHome(){
64
    eng.renderEngine.clearPage()
65
    eng.routesEngine.goToLink("http://127.0.0.1:5500/project/index.html#pageInitial")
66
}
67
68
//API
69
function Api(data) {  
70
    fetch('https://jsonplaceholder.typicode.com/posts/' + data)
71
        .then(response => response.json())
72
        .then(json => eng.renderEngine.changeContentElement("header0", json.title))
73
74
    fetch('https://jsonplaceholder.typicode.com/posts/' + data)
75
        .then(response => response.json())
76
        .then(json => eng.renderEngine.changeContentElement("contentBody", json.body))
77
}
78
79
let varLcoal=""
80
81
function HelloBase(name){
82
    varLcoal=name
83
    return ('<div> #{name} </div>')
84
}
85
86
function preRender(render){
87
    let varFunction = ""
88
    let varname=""
89
    let index=0
90
    while(render.length > index){
91
        if(render[index]=='#' && render[index+1]=='{'){
92
            while(render[index]!="}"){
93
                varFunction+=render[index]
94
                varname+=render[index]
95
                index++
96
            }
97
            if(render[index]=="}")varFunction+='}'
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
98
        }
99
        index++
100
    }
101
    render = render.replace(varFunction,varLcoal)
102
    return render
103
}
104
105
function render(base){
106
107
    return preRender(base)
108
}
109
110
document.getElementById("idHome").append(render(HelloBase("ola")))